/**
 * BilbaoUtils.h
 *
 * @author Bematech S.A.
 */

#ifndef __BILBAO_UTIL_XML_UTILS_CLASS_H__
#define __BILBAO_UTIL_XML_UTILS_CLASS_H__

#include "bilbao/types.h"
#include "bilbao/util/Tokenizer.h"

/*enum
{
	ERROR_ARGS,
	ERROR_XERCES_INIT,
	ERROR_PARSE,
	ERROR_EMPTY_DOCUMENT
};*/

#define X(value) xercesc::XMLString::transcode(value)

using namespace xercesc;

namespace bilbao
{
	namespace util
	{
		/**
		 * Classe utilitária para validar um documento XML com base em um DTD/Schema. O
		 * mapeamento de erros em regras de negócio deve ser efetuado pela classe que
		 * utilize XmlUtils
		 */
		class XmlUtils
		{
		public:

			/*
			 *
			 */
			XmlUtils();

			/*
			 *
			 */
			virtual ~XmlUtils();

			/*
			 *
			 */
			XML data2xml( String data );

			/*
			 *
			 */
			String getDigitalCertificate( XML xml );

			/*
			 *
			 */
			long getPeriodicityTime( XML useParameters );

			/*
			 *
			 */
			static void string2File( const String& outputFile, const String& str );

			/**
			 *
			 */
			int string2Mem( const String& xml, const String& memBufId, DOMDocument** doc ) const;

			/**
			 *
			 */
			int string2DOMDoc( const String& xml, DOMDocument** doc );

			/*
			 *
			 */
			static int file2String( const String& inputfile, String& ret );

			/*
			 *
			 */
			int file2Mem( const String& inputfile, const char* memBufId, DOMDocument** doc ) const;

			/**
			 *
			 */
			int DOMDoc2File( const DOMDocument* doc, const String& outputfile ) const;

			/**
			 *
			 */
			int DOMDoc2String( /*in*/const DOMDocument* doc, /*out*/String& outputStr ) const;

			/**
			 *
			 */
			DOMElement* addNewTag( DOMDocument** doc, DOMElement** parent, const String& tagName );

			/**
			 *
			 */
			void addNewTagRoot( DOMDocument** doc, const String& tagName, const String& value );

			/**
			 *
			 */
			int getElementByTagName( /*in*/const String& tagName, /*in*/const DOMDocument* doc, /*out*/DOMElement** element );

			/**
			 *
			 */
			int getElementByTagPath( /*in*/const String& pathName, /*in*/const DOMDocument* doc, /*out*/DOMElement** ret );
			
			/**
			 * Método criado a partir da macro homônima de AdCFe.cpp
			 */
			static void addAdcfe( XmlUtils& XMLUTILS, DOMDocument* DOC, DOMElement* PARENT_TAG_NODE,
					const String& TAG_NODE, const String& TAG_CONTENT, DOMElement* NODE);

			/**
			 * Método criado a partir da macro homônima de AdCFe.cpp
			 */
			static void addAdcfeNode( XmlUtils& XMLUTILS, DOMDocument* DOC, DOMElement* PARENT_TAG_NODE, const String& TAG_NODE, DOMElement* NODE);

			/**
			 * Método criado a partir da macro homônima de AdCFe.cpp
			 */
			static void conteudo( XmlUtils& XMLUTILS, DOMDocument* DOC,const String& PATH_TAG_NODE, DOMElement*/*out*/ELEMENT, String& /*in*/ CONTENT );

		private:
			///Configuração do parser
			XercesDOMParser* _configParser;
			///
			struct stat fileStatus;
			///
			//DOMLSSerializer* writer;
			///
			//DOMLSOutput* xmlstream;
			///
			DOMImplementation* mImplementation;

		};
	} // namespace util
} // namespace bilbao
#endif // __BILBAO_UTIL_XML_UTILS_CLASS_H__
